import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image

def predict():
    img_path = "/home/a1/qt/CHAT/Server/temp.png"
    # 加载模型
    model = keras.models.load_model("./model.h5")
    # 加载图片
    img = keras.preprocessing.image.load_img(
        img_path, color_mode="grayscale", target_size=(28, 28)
    )

    img_arr = np.array(img)
    img_arr = img_arr / 255.0  
    img_arr = img_arr.reshape(1, 28, 28, 1)  
   
    # 进行预测
    pred = model.predict(img_arr)
    print(np.argmax(pred)) 


predict()
